package cate.game.role.mall.refresh.impl;

import cate.game.GameBody;
import cate.game.role.mall.RefreshTimeCheck;
import cate.game.role.mall.refresh.item.RefreshItem;
import org.apache.commons.lang3.StringUtils;

public interface IAutoRefresh {
    RefreshItem getAutoRefreshItem();

    String getAutoCycle();

    default boolean checkAutoCycle(GameBody gameBody) {
        String autoCycle = getAutoCycle();
        if (StringUtils.isBlank(autoCycle)) {
            return false;
        }
        RefreshItem refreshItem = getAutoRefreshItem();
        if (refreshItem == null) {
            return false;
        }
        if (RefreshTimeCheck.isRefresh(gameBody, refreshItem.getLastRefreshTime(), autoCycle)) {
            refreshItem.updateRefreshItem(System.currentTimeMillis(),0);
            return true;
        }
        return false;
    }
}
